﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using MMITWeb.Models;
using MMITCore;
using MMITCore.CurrencyConverter;
using MMITCore.Logging;
using MMITDomain.Abstract;
using MMITDomain.Entities;
using System.Text;
using MMITWeb.Infrastructure.Abstract;
using MMITCore.Abstract;
using MMITWeb.MMITCoreService;

namespace MMITWeb.Controllers
{
    [Authorize]
    public class TransactionsController : Controller
    {
        CoreServiceClient client;
        ICustomerRepository customerRepository;
        ITransactionRepository transactionRepository;
        ICountryRepository countryRepository;
        IIdentificationTypeRepository identificationTypeRepository;
        IPartnerRepository partnerRepository;
        IChargeRepository chargeRepository;
        IAccountRepository accountRepository;
        INotificationManager notificationManager;
        ResponseObject ro;
        ILogger<SynkronLogger> _logger;

        public TransactionsController(ICustomerRepository customerRepository, ITransactionRepository transactionRepository,
            ICountryRepository countryRepository, IIdentificationTypeRepository identificationTypeRepository,
            IAccountRepository accountRepository, IChargeRepository chargeRepository, INotificationManager notificationManager, ILogger<SynkronLogger> logger,
            IPartnerRepository partnerRepository)
        {
            this.customerRepository = customerRepository;
            this.transactionRepository = transactionRepository;
            this.identificationTypeRepository = identificationTypeRepository;
            this.countryRepository = countryRepository;
            this.chargeRepository = chargeRepository;
            this.accountRepository = accountRepository;
            this.notificationManager = notificationManager;
            this.partnerRepository = partnerRepository;
            _logger = logger;

            client = new CoreServiceClient();
            
            ro = new ResponseObject();
        }

        [HttpPost]
        [ValidateAntiForgeryToken(Salt = "sendmoneysalt")]
        public ActionResult SendMoney(SendMoneyViewModel model)
        {
            //Repopulate drop downs....
            model.Countries = countryRepository.Countries.ToList().Select(x => new Telerik.Web.Mvc.UI.DropDownItem
            {
                Text = x.Name,
                Value = x.Id.ToString()
            });

            model.IdentificationTypes = from idents in identificationTypeRepository.IdentificationTypes.ToList()
                                        select new Telerik.Web.Mvc.UI.DropDownItem
                                        {
                                            Text = idents.Name,
                                            Value = idents.Id.ToString()
                                        };
            model.Accounts = from accs in customerRepository.GetCustomerByUsername(User.Identity.Name).Accounts.ToList()
                             select new Telerik.Web.Mvc.UI.DropDownItem
                             {
                                 Text = accs.Name,
                                 Value = accs.Id.ToString()
                             };
            model.Beneficiaries = from t in transactionRepository.GetCustomerTransactions(customerRepository.GetCustomerByUsername(User.Identity.Name)).ToList()
                                  where t.TransactionType.Id == (int)TransactionTypes.P2PUnregistered
                                  && t.Status == (int)TransactionStatuses.Completed
                                  select new Telerik.Web.Mvc.UI.DropDownItem
                                  {
                                      Text = string.Format("{0} {1}", t.Recipient.Customer.Firstname, t.Recipient.Customer.Lastname),
                                      Value = t.Recipient.Id.ToString()
                                  };

            model.Partners = from p in partnerRepository.Partners.ToList()
                           select new Telerik.Web.Mvc.UI.DropDownItem
                           {
                               Text = p.Name,
                               Value = p.Id.ToString()
                           };
            try
            {
                if (ModelState.IsValid)
                {
                    //get Account Currency
                    Account objAccount = accountRepository.GetAccountById(model.AccountId);

                    string senderCurrency = accountRepository.GetAccountCurrency(objAccount).ISOCode;
                    string recipientCurrency = countryRepository.GetDefaultCurrency(countryRepository.GetCountryById(model.CountryId)).ISOCode;


                    //ToDo: Select Transaction Type based on registered or unregistered recipient
                    //var charges = chargeRepository.GetChargesByTransactionType(TransactionTypes.P2PUnregistered).ToList();

                    decimal totalCharges = 0.00M;
                    decimal totalValue = 0.00M;
                    TransactionCharges charges;

                    CalculateCharges(model.Amount, TransactionTypes.P2PUnregistered, out totalCharges, out totalValue, out charges);

                    var x = ExchangeRateCalculator.Convert(totalValue, senderCurrency, recipientCurrency);

                    if (objAccount.ActualBalance > totalValue)
                    {
                        SendMoneyConfirmationViewModel k = new SendMoneyConfirmationViewModel
                        {
                            BaseAmount = model.Amount,
                            FxAmount = x,
                            Charges = charges.txnCharges,
                            TotalValue = totalValue,
                            TotalCharges = totalCharges,
                            sendMoneyViewModel = model,
                            SenderCurrency = senderCurrency,
                            RecipientCurreny = recipientCurrency
                        };

                        Session["model"] = k;

                        return View("SendMoneyConfirmation", k);
                    }
                    else
                    {
                        ModelState.AddModelError("3000010", string.Format("Error Total Value of Transaction exceeds total account balance"));

                        _logger.WriteError(3000010, () => string.Format("Error Completing Transaction : [{0}] Reason : Total Value of Transaction exceeds total account balance", ro.Description), new Dictionary<string, object> {
                            {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                            {string.Format("Core Response :"), _logger.Desc(ro)},
                            {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                        });
                        return View(model);

                    }

                }

            }
            catch (Exception Ex)
            {
                //Log Exception
                ModelState.AddModelError("3000011", string.Format("Error Completing Transaction : Code [{0}]", 3000011));

                _logger.WriteError(3000011, () => string.Format("Error Completing Transaction"), Ex,
                      new Dictionary<string, object> {
                            {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(this)},
                            {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                        });
            }

            return View(model);
        }


        public ViewResult SendMoneyConfirmation(SendMoneyConfirmationViewModel model)
        {
            return View(model);
        }

        public ViewResult SendMoneyComplete()
        {
            SendMoneyConfirmationViewModel model = (SendMoneyConfirmationViewModel)Session["model"];

            try
            {

                ro = client.SendMoney(null, null, model.sendMoneyViewModel.AccountId, 0, string.Format("{0}{1}", model.sendMoneyViewModel.CountryCode, model.sendMoneyViewModel.RecipientMSISDN), model.sendMoneyViewModel.Amount,
                    model.sendMoneyViewModel.FirstName, model.sendMoneyViewModel.LastName, model.IdentificationTypeId,
                    model.sendMoneyViewModel.IdentificationNumber, model.CountryId,(int)SendMoneyRecipientType.Mobipay,model.sendMoneyViewModel.PartnerId);

                ViewData["message"] = String.Empty;

                switch (ro.ResponseCode)
                {
                    case 0:
                        ViewData["message"] = "Transaction Completed Successfully";
                        //notify recipient by sms...
                        Customer sender = customerRepository.GetCustomerByUsername(HttpContext.User.Identity.Name);
                        notificationManager._notificationType = Infrastructure.Concrete.NotificationType.SMSNotification;
                        notificationManager.SendShortMessage(string.Format("{0}{1}", model.sendMoneyViewModel.CountryCode, model.sendMoneyViewModel.RecipientMSISDN), string.Format("You have received {0} from {1} {2}", model.sendMoneyViewModel.Amount, sender.Firstname, sender.Lastname));

                        _logger.WriteInformation(3000001, () => "Send Money Successful", new Dictionary<string, object> { 
                            {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                            {string.Format("Core Response :"), _logger.Desc(ro)}
                        });
                        
                        break;
                    case 4: //system error
                         ViewData["message"] = string.Format("Error Completing Transaction : [{0}]", ro.Description);
                        
                        _logger.WriteError(3000024, () => string.Format("Error Completing Transaction : [{0}]", ro.Description), new Dictionary<string, object> {
                            {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                            {string.Format("Core Response :"), _logger.Desc(ro)},
                            {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                        });
                        
                        break;
                    default:
                        ViewData["message"] = string.Format("Error Completing Transaction : [{0}]", ro.Description);
                        
                        _logger.WriteError(3000002, () => string.Format("Error Completing Transaction : [{0}]", ro.Description), new Dictionary<string, object> {
                            {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                            {string.Format("Core Response :"), _logger.Desc(ro)},
                            {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                        });
                        
                        break;

                }
            }
            catch (Exception Ex)
            {
                ViewData["message"] = string.Format("Error Completing Transaction : [{0}]", Ex.Message);

                _logger.WriteError(3000003, () => string.Format("Error Completing Transaction : [{0}]", ro.Description), Ex,
                    new Dictionary<string, object> {
                            {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                            {string.Format("Core Response :"), _logger.Desc(ro)},
                            {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                        });
            }
            return View(model);
        }


        public ViewResult SendMoney()
        {
            //Get countries...
            var countries = countryRepository.Countries.ToList().Select(x => new Telerik.Web.Mvc.UI.DropDownItem
            {
                Text = x.Name,
                Value = x.Id.ToString()
            });


            //Get Identification Types...
            var identifications = from idents in identificationTypeRepository.IdentificationTypes.ToList()
                                  select new Telerik.Web.Mvc.UI.DropDownItem
                                  {
                                      Text = idents.Name,
                                      Value = idents.Id.ToString()
                                  };

            //Get Sender Accounts
            var accounts = from accs in customerRepository.GetCustomerByUsername(User.Identity.Name).Accounts.ToList()
                           select new Telerik.Web.Mvc.UI.DropDownItem
                           {
                               Text = accs.Name,
                               Value = accs.Id.ToString()
                           };
            var recipients = from t in transactionRepository.GetCustomerTransactions(customerRepository.GetCustomerByUsername(User.Identity.Name)).ToList()
                             where t.TransactionType.Id == (int)TransactionTypes.P2PUnregistered
                             && t.Status == (int)TransactionStatuses.Completed
                             select new Telerik.Web.Mvc.UI.DropDownItem
                             {
                                 Text = string.Format("{0} {1}", t.Recipient.Customer.Firstname, t.Recipient.Customer.Lastname),
                                 Value = t.Recipient.Id.ToString()
                             };
            
            var partners = from p in partnerRepository.Partners.ToList()
                           select new Telerik.Web.Mvc.UI.DropDownItem
                           {
                               Text = p.Name, Value = p.Id.ToString()
                           };

            SendMoneyViewModel model = new SendMoneyViewModel()
            {
                Countries = countries,
                IdentificationTypes = identifications,
                Accounts = accounts,
                Beneficiaries = recipients,
                Partners = partners
            };
            return View(model);
        }


        public ViewResult LoadMoney()
        {
            //get logged in customer id 
            Customer objCustomer = (from c in customerRepository.Customers
                                    where c.Username == HttpContext.User.Identity.Name
                                    select c).SingleOrDefault<Customer>();
            //get customer account(s)
            var accounts = from c in objCustomer.Accounts
                           select new Telerik.Web.Mvc.UI.DropDownItem
                           {
                               Text = c.Name,
                               Value = c.Id.ToString()
                           };
            ViewBag.Accounts = accounts.ToList();
            return View();
        }

        [HttpPost]
        [ValidateAntiForgeryToken(Salt = "loadmoneysalt")]
        public ActionResult LoadMoney(LoadMoneyViewModel model)
        {
            try
            {
                //get wallet currency..
                var p = accountRepository.GetAccountById(model.id);

                //wallet currency and voucher currency must be the same..
                if (p.Currency.ISOCode != model.Currency)
                    ModelState.AddModelError("","Wallet Currency must match Voucher Currency");

                if (ModelState.IsValid)
                {
                    //the load money method should be refactored to accept Voucher and Account objects..
                    switch (model.GATEWAY)
                    {
                        case "1":
                            //MMIT Voucher...
                            ro = client.LoadMoney(model.SerialNo, model.PIN, model.id);
                            switch(ro.ResponseCode){

                                case 0: //success
                                _logger.WriteInformation(3000016, () => "Load Money Successful", new Dictionary<string, object> { 
                                    {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                                    {string.Format("Core Response :"), _logger.Desc(ro)},
                                    {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                                });
                                    break;
                                case 1: //invalid voucher
                                    _logger.WriteWarning(3000017, () => "Load Money Failure", new Dictionary<string, object> { 
                                    {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                                    {string.Format("Core Response :"), _logger.Desc(ro)},
                                    {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                                });
                                    break;

                                case 11:
                                    _logger.WriteWarning(3000018, () => "Load Money Failure", new Dictionary<string, object> { 
                                    {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                                    {string.Format("Core Response :"), _logger.Desc(ro)},
                                    {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                                });
                                    break;

                                case 4: //system error
                                    _logger.WriteWarning(3000019, () => "Load Money Failure", new Dictionary<string, object> { 
                                    {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                                    {string.Format("Core Response :"), _logger.Desc(ro)},
                                    {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                                });
                                    break;
                                case 5:
                                    _logger.WriteWarning(3000020, () => "Load Money Failure", new Dictionary<string, object> { 
                                    {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                                    {string.Format("Core Response :"), _logger.Desc(ro)},
                                    {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                                });
                                    break;
                                default: // unknown response code
                                    _logger.WriteWarning(3000022, () => "Load Money Failure : Unknown Response Code", new Dictionary<string, object> { 
                                    {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                                    {string.Format("Core Response :"), _logger.Desc(ro)},
                                    {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                                });
                                    break;
                    }

                            break;

                        case "2":
                            //UKash Voucher...
                            ro = client.LoadMoneyExternal(model.UkashPIN, model.id, model.Amount, model.Currency);

                            switch (ro.ResponseCode)
                            {
                                case 0: //success
                                    _logger.WriteInformation(3000005, () => "Load Money External Successful", new Dictionary<string, object> { 
                                    {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                                    {string.Format("Core Response :"), _logger.Desc(ro)},
                                    {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                                });
                                    break;
                                case 1: //invalid voucher
                                    _logger.WriteWarning(3000012, () => "Load Money External Failure", new Dictionary<string, object> { 
                                    {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                                    {string.Format("Core Response :"), _logger.Desc(ro)},
                                    {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                                });
                                    break;
                                case 11: //unknown account
                                    _logger.WriteWarning(3000013, () => "Load Money External Failure", new Dictionary<string, object> { 
                                    {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                                    {string.Format("Core Response :"), _logger.Desc(ro)},
                                    {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                                });
                                    break;
                                case 5: //Negative Transaction Value
                                    _logger.WriteWarning(3000014, () => "Load Money External Failure", new Dictionary<string, object> { 
                                    {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                                    {string.Format("Core Response :"), _logger.Desc(ro)},
                                    {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                                });
                                    break;
                                case 4: // system error
                                    _logger.WriteWarning(3000021, () => "Load Money External Failure", new Dictionary<string, object> { 
                                    {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                                    {string.Format("Core Response :"), _logger.Desc(ro)},
                                    {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                                });
                                    break;
                                default: // unknown response code
                                    _logger.WriteWarning(3000023, () => "Load Money External Failure : Unknown Response Code", new Dictionary<string, object> { 
                                    {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                                    {string.Format("Core Response :"), _logger.Desc(ro)},
                                    {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                                });
                                    break;
                            }
                            break;

                        default:
                            _logger.WriteInformation(3000006, () => "Switch Case Default Case | Empty Code", new Dictionary<string, object> { 
                            {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                            {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}                            
                        });
                            break;
                    }

                    return PartialView("_CoreResponsePartial", new List<string>() { string.Format("Status Code :{0} | {1}", ro.ResponseCode, ro.Description) });
                }
            }
            catch (Exception Ex)
            {
                _logger.WriteError(3000007, () => string.Format("Error Completing Transaction : [{0}]", ro.Description), Ex,
                    new Dictionary<string, object> {
                            {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                            {string.Format("Core Response :"), _logger.Desc(ro)},
                            {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                        });

                ModelState.AddModelError("3000007", string.Format("Error Completing Transaction : Code [{0}]", 3000007));
            }

            var errors = from v in ModelState.Values.ToList()
                         where v.Errors.Count > 0
                         select v.Errors;

            return PartialView("_ResponsePartial", errors);
        }

        public ActionResult GatewayHandler(string GatewayId)
        {
            string strPartialViewName = string.Empty;

            switch (GatewayId)
            {
                //MMIT 
                case "1":
                    strPartialViewName = "_MMITVoucherPartial";
                    break;

                //UKASH
                case "2":
                    strPartialViewName = "_UKASHVoucherPartial";
                    break;

            }

            return PartialView(strPartialViewName);
        }

        public JsonResult StoredBeneficiaryHandler(int RecipientId)
        {
            var p = accountRepository.GetAccountById(RecipientId);

            return Json(new
            {
                FirstName = p.Customer.Firstname,
                LastName = p.Customer.Lastname,
                Mobile = p.Customer.Mobile,
                IdentTypeId = p.Customer.IdentificationTypeId,
                CountryId = p.Customer.CountryId,
                IdentNumber = p.Customer.IdentificationNumber,
                Currency = p.Currency.ISOCode
            },
                JsonRequestBehavior.AllowGet);
        }


        [HttpPost]
        public ActionResult RequestWithdrawalToken(RequestTokenViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    ro = client.RequestToken(model.Amount, customerRepository.GetCustomerByUsername(User.Identity.Name)
                        .Mobile);

                    return PartialView("_CoreResponsePartial", new List<string>() { ro.Description , 
                        string.Format("Your Withdrawal Token is: [{0}]",ro.TransactionCode)});
                }
            }
            catch (Exception Ex)
            {
                _logger.WriteError(3000008, () => string.Format("Error Completing Transaction : [{0}]", ro.Description), Ex,
                    new Dictionary<string, object> {
                            {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(model)},
                            {string.Format("Core Response :"), _logger.Desc(ro)},
                            {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                        });
            }

            var errors = from v in ModelState.Values.ToList()
                         where v.Errors.Count > 0
                         select v.Errors;

            return PartialView("_ResponsePartial", errors);
        }


        public ViewResult RequestWithdrawalToken()
        {
            return View();
        }

        public ViewResult Reports()
        {
            //Get Transactions for Logged in User....
            var transactions = transactionRepository.GetCustomerTransactions(customerRepository.Customers
                                                                        .Where(c => c.Username == User.Identity.Name)
                                                                        .SingleOrDefault<Customer>());

            _logger.WriteInformation(3000009, () => "Transaction Reports Loaded Successful", new Dictionary<string, object> { 
                            {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(transactions)},
                            {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                        });
            return View(transactions);
        }

        public ActionResult Success()
        {
            return View();
        }

        public void CalculateCharges(decimal amount, TransactionTypes transactionType, out decimal totalCharges, out decimal totalValue, out TransactionCharges charges)
        {
            totalCharges = 0.00M;
            totalValue = 0.00M;
            charges = null;
            try
            {
                charges = client.GetTransactionCharges(amount, (int)TransactionTypes.P2PUnregistered);
                foreach (var item in charges.txnCharges)
                {
                    totalCharges = totalCharges + (decimal)item.Amount;
                }
                totalValue = (amount - totalCharges);
            }
            catch (Exception Ex)
            {
                _logger.WriteCritical(3000015, () => "Core Service Method Failure", Ex, new Dictionary<string, object> { 
                            {string.Format("Logon User: {0} IPADRR: {1}", User.Identity.Name, Request.ServerVariables["REMOTE_ADDR"]),_logger.Desc(Ex)},
                            {string.Format("Action Method : {0}",this.ControllerContext.RouteData.GetRequiredString("action")),_logger.Desc(this.ControllerContext)}
                        });
            }
        }
    }
}
